package com.leetcode;

/**
 * 303. 区域和检索 - 数组不可变
 * 前缀和
 *
 * @author fy
 * @date 2022-05-16 21:01
 */
public class Solution303 {

    class NumArray {

        private int[] sums;

        public NumArray(int[] nums) {
            int n =  nums.length + 1;
            sums = new int[n];
            sums[0] = 0;
            for (int i = 1; i < n; i++) {
                sums[i] = sums[i - 1] + nums[i - 1];
            }
        }

        public int sumRange(int left, int right) {
            return sums[right + 1] - sums[left];
        }
    }

}
